<%@page import="com.shsh.safemanage.model.WeakUserReportComparatorByPointSum"%>
<%@page import="java.util.Collections"%>
<%@page import="com.shsh.safemanage.dao.UserDao"%>
<%@page import="com.shsh.safemanage.model.Problem"%>
<%@page import="com.shsh.safemanage.dao.ProblemDao"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.dao.DepartmentDao"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%@page import="com.shsh.safemanage.model.WeakProblem"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.model.WeakUserReport"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.model.WeakReport"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.RequestUtil"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.dao.WeakDao"%>
<%@page language="java" pageEncoding="UTF-8"%>
<%
	{
	Long depart1ID = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_DEPARTMENT1ID, (Long)null);
	Integer year = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_YEAR, (Integer)null);
	Integer month = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_MONTH, (Integer)null);
	
	WeakDao weakDao = DaoCreator.createWeakDao();
	DepartmentDao departDao = DaoCreator.createDepartmentDao();
	ProblemDao problemDao = DaoCreator.createProblemDao();
	UserDao userDao = DaoCreator.createUserDao();
	
	Department1 depart1 = departDao.getDepartment1ByID(depart1ID);
	
	int[][] pointTable = new int[12][3];
	
	WeakReport theWeakReport = weakDao.getDanweiWeakReport(year, month, depart1ID);
	if(theWeakReport==null){
		return ;
	}
	pointTable[month-1][0]=theWeakReport.getPointSum();
	pointTable[month-1][1]=theWeakReport.getUserCount();
	pointTable[month-1][2]=theWeakReport.getPointAverage();
	
	for(int i=1;i<=12;i++){
		//if(i!=month) {
			WeakReport tmpWeakReport = weakDao.getDanweiWeakReport(year, i, depart1ID);
			if(tmpWeakReport==null){
				continue ;
			}
			if(tmpWeakReport.getPointSum()==0 && tmpWeakReport.getUserCount()==0&&tmpWeakReport.getPointAverage()==0) {
				WeakReport.setPointTable(tmpWeakReport);
			}
			pointTable[i-1][0]=tmpWeakReport.getPointSum();
			pointTable[i-1][1]=tmpWeakReport.getUserCount();
			pointTable[i-1][2]=tmpWeakReport.getPointAverage();
		//}
	}
	
	Problem theProblem = problemDao.getProblemByID(theWeakReport.getProblemID());
	User writer = userDao.getUserByID(theProblem.getWriteUserID());
	User closer = userDao.getUserByID(theProblem.getCloseUserID());
	

	List<WeakUserReport> userReportList=theWeakReport.getGuanliReportList();
	userReportList.addAll(theWeakReport.getYixianReportList());
	userReportList.addAll(theWeakReport.getNotWrittenGuanliReportList());
	
	Collections.sort(userReportList, WeakUserReportComparatorByPointSum.getInstance());
%>
<div class="content" style="">
<div class="tt"><%=year %>年<%=month %>  月<%=depart1.getDepartmentName() %>“查找身边十大薄弱环节”积分台帐</div>
<table border="1" width="99%" style="align:center; margin-left: 6px;margin-top:10px;">
	<tr>
		<td rowspan="2" style="text-align:center;width:6%;" class="td3">
		姓名
		</td>
		<td rowspan="2" style="text-align:center;width:3%;" class="td3">
		序号
		</td>
		<td rowspan="2" style="text-align:center;width:22%;" class="td3">
		薄弱环节描述
		</td>
		<td rowspan="2" style="text-align:center;width:22%;" class="td3">
		改进对策与措施
		</td>
		<td rowspan="2" style="text-align:center;width:12%;" class="td3">
		薄弱环节分类
		</td>
		<td rowspan="2" style="text-align:center;width:5%;" class="td3">
		积分
		</td>
		<td colspan="2" style="text-align:center;width:15%;" class="td3">
		备注
		</td>
		<td rowspan="2" style="text-align:center;width:5%;" class="td3">
		累计积分
		</td>
	</tr>
	<tr>
		<td style="text-align:center;width:5%;" class="td3">
		扣分值
		</td>
		<td style="text-align:center;width:10%;" class="td3">
		8:00--16:30以外时间
		</td>
	</tr>
<%

for(int index = 0; index < userReportList.size(); index++) {
	WeakUserReport userReport = userReportList.get(index);
	User user = theWeakReport.getUserMap().get(userReport.getUserID());
	int size = userReport.getProblemList().size();
	int pointSum = userReport.getPointSum();
	boolean isFirstRow = true;
%>
<%
	for(int index2=0;index2<userReport.getProblemList().size();index2++) {
		WeakProblem p =  userReport.getProblemList().get(index2);
		boolean canCheckWeakType = false;
		boolean displayRedPoint = false;
		if(p.getProblemType()==null || p.getGrade()==null || p.getGrade()==0){
			canCheckWeakType=true;
		}
		if(p.getWeakType()!=2 || p.hasNoneWorkTime()){
			displayRedPoint = true;
		}
		if(isFirstRow) {
%>
	<tr>
		<td rowspan="<%=size%>" style="text-align:center;">
		<%=Util.getDisplay(user.getName(), "&nbsp;") %>
		</td>
<%
		}
%>
		<td style="text-align:center;<%=p.isNeedDelete()?"background:gray;":""%>">
		<%=index2+1 %>
		</td>
		<td style="text-align:left;padding-left:5px;<%=p.isNeedDelete()?"background:gray;":""%>">
		<%=Util.getDisplay(p.getProblemContent(), "&nbsp;") %>
		</td>
		<td style="text-align:left;padding-left:5px;<%=p.isNeedDelete()?"background:gray;":""%>">
		<%=Util.getDisplay(p.getProblemZhenggai(), "&nbsp;") %>
		</td>
		<td style="text-align:center;<%=canCheckWeakType?"":"background-color:gray;" %><%=p.isNeedDelete()?"background:gray;":""%>">
<%
		if(p.getWeakType()==0) {
%>
A
<%
		} else if(p.getWeakType()==1) {
%>
B
<%
		}else if(p.getWeakType()==2) {
%>
C
<%
		}
%>

		</td>
		<td style="text-align:center;<%=displayRedPoint?"color:red;":""%><%=p.isNeedDelete()?"background:gray;":""%>">
		<%=Util.getDisplay(Util.formatGrade(p.getPoint()), "&nbsp;") %>
		</td>
		<td style="text-align:center;<%=p.isNeedDelete()?"background:gray;":""%>">
		<%=Util.getDisplay(p.getGrade()==null?null:Util.formatGrade(p.getGrade()), "&nbsp;") %>
		</td>
		<td style="text-align:left;<%=p.isNeedDelete()?"background:gray;":""%>">
		<input disabled="disabled" type="checkbox" id="noneWorkTimeCheck<%=p.getId()%>" name="noneWorkTimeCheck<%=p.getId()%>" onclick="checkNoneWorkTime(<%=p.getId()%>)" <%=p.hasNoneWorkTime()?"checked=\"checked\"":"" %> value=""/>
		<label style="text-decoration:underline;" for="noneWorkTimeCheck<%=p.getId()%>"><%=Util.getDisplay(p.getNoneWorkTime(), "") %></label>
		</td>
<%
		if(isFirstRow) {
%>
		<td rowspan="<%=size%>" style="text-align:center;">
		<%=Util.getDisplay(Util.formatGrade(pointSum), "&nbsp;") %>
		</td>
<%
		}
%>
	</tr>
<%
		isFirstRow = false;
	}
}
%>

	<tr>
		<td colspan="2" style="text-align:center;" class="td3">
		负责人及审批日期
		</td>
		<td style="text-align:center;" class="td3">
			<%=Util.getDisplay(closer.getName(), "") %>&nbsp;&nbsp;<%=Util.getDisplay(Util.formatDate(theProblem.getCloseTime()), "") %>
		</td>
		<td colspan="2" style="text-align:center;" class="td3">
		汇总人及汇总日期
		</td>
		<td colspan="4" style="text-align:center;" class="td3">
			<%=Util.getDisplay(writer.getName(), "") %>&nbsp;&nbsp;<%=Util.getDisplay(Util.formatDate(theProblem.getWriteTime()), "") %>
		</td>
	</tr>
</table>
<div>
<div class="tt"><%=year %>年<%=month %>  月<%=depart1.getDepartmentName() %>“查找身边十大薄弱环节”平均积分</div>
<table border="1" width="99%" style="align:center; margin-left: 6px;margin-top:10px;">
	<tr>
		<td style="text-align:center;width:18%;" class="td3">
		月份
		</td>
<%
for(int i=0;i<12;i++) {
%>
		<td style="text-align:center;width:6%;" class="td3">
			<%=i+1 %>
		</td>
<%
}
%>
	</tr>
	<tr>
		<td style="text-align:center;" class="td3">
		累计积分
		</td>
<%
for(int i=0;i<12;i++) {
%>
		<td style="text-align:center;">
			<%=Util.formatGrade(pointTable[i][0]) %>
		</td>
<%
}
%>
	</tr>
	<tr>
		<td style="text-align:center;" class="td3">
		人数
		</td>
<%
for(int i=0;i<12;i++) {
%>
		<td style="text-align:center;" >
			<%=pointTable[i][1] %>
		</td>
<%
}
%>
	</tr>
	<tr>
		<td style="text-align:center;" class="td3">
		平均积分
		</td>
<%
for(int i=0;i<12;i++) {
%>
		<td style="text-align:center;" >
			<%=Util.formatGrade(pointTable[i][2]) %>
		</td>
<%
}
%>
	</tr>
</table>
<table>
		<tr>
			<td class="td1" height="35" colspan="10">
				<input type="button" style="margin-left: 45%;" value="返 回" onclick="goBack()" />
			</td>
		</tr>
</table>
</div>
</div>
<script type="text/javascript">
function goBack(){
	loadPageSection('<%=request.getContextPath()%>/weak/read_corp_report.jsp', 'mainContentDiv', {year: <%=year%>}, true);
}
</script>
<%
}
%>